<html>
<head>
<title>Card Generator</title>
<script type='text/javascript' src='helper.js'></script>
</head>
<body>

<script type='text/javascript'>
//document.write('<pre>');

var limit = 24;
var str = 'Well, Here is a test sentence. Whether it wraps or not needs to be seen.';
//var str = 'Well,_Here_is_a_test_sentence._Whether_it_wraps_or_not_needs_to_be_seen.';
document.write('<br>' + str);
document.write('<br>');
document.write('<br>');
var tst = str;
var flag = true;
var ar = [];
var pos;
var tmp;
while(flag) {
	if(tst.length > (limit-1)) {
		if(tst[limit] == ' ') {
			tmp = tst.substr(0,limit-1);
			ar.push(tmp);
			tst = tst.substr(limit);
		} else {
			tmp = tst.substr(0,limit-1);
			pos = strrpos(tmp,' ');
			if(false === pos) {
				ar.push(tmp);
				tst = tst.substr(limit);
			} else {
				ar.push(tst.substr(0,pos));
				tst = tst.substr(pos);
				//tst = trim(tst.substr(pos));
			}
		}
	} else {
		ar.push(tst);
		flag = false;
	}
}
document.write('<br>' + ar[0]);
document.write('<br>' + ar[1]);
document.write('<br>' + ar[2]);
document.write('<br>' + ar[3]);
document.write('<br>' + ar[4]);


data = '<div style="width:2in; height:1in; border: thin solid red; padding: 0px;">';
for(var i=0;i<ar.length;i++) {
	data += '<div class="font14" style="border: thin solid #000;width:2in;" >'+ar[i]+'</div>';
}
data += '</div>';
document.write('<pre>');
document.write(data);


/*
var height = 2;
var no = Math.floor(10/height);
var n = no-1;

if(((no * height) + (n * (1/6)) + (no * .014)) > 10) {
	no = n;
}

var data;
var ar = [];
//data = '<div style="width:1in; height:1in; border: thin solid #000; padding: 0px;">'
for(var i=0; i < no; i++) {
	ar.push('<div class="font14" style="border: thin solid #000;height:'+ height +'in;width:8in;" >12345678901234</div>');
}
data = '<div style="width:8.5in; height:11in; border: thin solid red; padding: 0px;">'
+'<div class="font14" style="border: thin solid #000;height:.5in;width:8.5in;" >Gap</div>'
+ ar.join('<br>')
+'<div class="font14" style="border: thin solid #000;height:.5in;width:8.5in;" >Gap</div>'
+'</div>';
document.write('<pre>');
document.write(data);
*/
</script>

</body>
</html>